#ifndef __NETWORKMUSICSTREAM_H__
#define __NETWORKMUSICSTREAM_H__

#include <Common/NetworkSocket.h>
#include "NetworkEngine/NetworkMusicFile.h"
#include "NetworkEngine/NetworkFileManager.h"

namespace SPlayer
{
    namespace Music
    {
        using namespace Network;
        ref class NetworkMusicStream : System::IO::Stream
        {
        public:
            NetworkMusicStream(System::String ^musicTitle)/* : filename(filename)*/
            {
                file = NetworkFileManager<NetworkMusicFile>::globalManager->getFile(musicTitle);
            }
            virtual int Read(array<unsigned char> ^buffer, System::Int32 offset, System::Int32 count) override
            {
                return file->read(buffer, offset, count);
            }
            virtual void Write(array<unsigned char, 1> ^, int, int) override
            { }
            virtual long long Seek(long long offset, System::IO::SeekOrigin origin) override
            {
                return file->seek(static_cast<int>(offset), origin);
            }
            property bool CanRead{bool get()override {return file->isReadable((int)Position, 1); } }
            property bool CanSeek{bool get()override {return true; } }
            property bool CanWrite{bool get()override {return false; } }
            //property long long Length{long long get()override {return 0;} }
            property long long Length{long long get()override {return file->currentReceivePosition;} }
            //property long long Position{long long get()override {return 0; }void set(long long)override {return ; } }
            property long long Position{long long get()override {return file->readPosition; }void set(long long newpos)override {Seek(newpos, IO::SeekOrigin::Begin); } }
            void SetLength(long long) override
            {
                ;
            }
            void Flush() override
            {
                ;
            }
        private:
            NetworkMusicFile ^file;
        };
    }
}

#endif // __NETWORKMUSICSTREAM_H__